package com.jdz.noise.controller;

import com.jdz.noise.entities.FlyRow;
import com.jdz.noise.entities.NoiseRow;
import com.jdz.noise.tools.ControlUtil;
import com.jdz.noise.tools.SphereAlg;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;

import static com.jdz.noise.tools.ControlUtil.*;

@Controller
public class DataAnalysisController {

    //三维声学球数据显示
    @RequestMapping("/constructBall")
    @ResponseBody
    public String constructBall() throws InterruptedException,Exception {

        //时间同步
        double[] ground_gps = {29, 0, 0, 117, 0, 0, 240};
        double ori = 54350;
        double freq = 30;
        Map<NoiseRow, FlyRow> res1 = ControlUtil.sync(ground_gps, ori, freq);

        //获取点升压集合
        SphereAlg.arc();
        //
        String res = SphereAlg.getSphereAlg();
        System.out.println(res);
        System.out.println("123");
        return res;
    }


    //原始数据显示
    @RequestMapping("/originDataDisPlay")
    @ResponseBody
    public String OriginDataDisPlay() {
        return getOrginData(list_noise);
    }

    //时间同步
    @RequestMapping("/sync")
    @ResponseBody
    public String sync(@RequestBody Map<String, String> reqMap) {
        System.out.println(reqMap);
        syncDatatrans(reqMap);
        return "{\"code\":0, \"msg\":\"success\"}";

    }

    @RequestMapping("/member-3DNoise")
    public String member_3DNoise() {

        return "member-3DNoise.html";
    }

    @RequestMapping("/refresh-3DNoise")
    @ResponseBody
    public String refresh_3DNoise(@RequestBody LinkedHashMap reqMap) {
        System.out.println("hello refresh-3DNoise");
        //System.out.println(reqMap);
        temp_3D_noise(reqMap);
        return "{\"code\":0, \"msg\":\"success\"}";

    }

    @GetMapping("/test")
    public ModelAndView test() {
        ModelAndView md = new ModelAndView();
        md.setViewName("/index.html");
        return md;
    }
}
